package com.gexin.controller.system.agent;


import com.gexin.common.model.ApiResponse;
import com.gexin.common.utils.StringUtil;
import com.gexin.core.web.SystemBaseController;
import com.gexin.model.agent.Agent;
import com.gexin.model.agent.AgentLevel;
import com.gexin.service.agent.AgentService;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Page;

import java.util.List;

@ControllerBind(controllerKey = "/system/agent/level", viewPath = "WEB-INF/system/agent/")
public class AgentLevelController  extends SystemBaseController {

	public void index(){
		if(isAjax()){
			Page<AgentLevel> levelPageList = AgentService.dao.findLevelPageList(getpage() , getpageSize());
			renderJson(levelPageList);
			return;
		}
		render("agent_level.html");
	}

	/**
	 * 保存代理商等级
	 */
	public void saveLevel(){
		AgentLevel level = getModel(AgentLevel.class , "level");
		ApiResponse apiResponse = AgentService.dao.saveAgentLevel(level);
		renderJson(apiResponse);
	}

	/**
	 * 获取所有代理商等级
	 */
	public void findAll(){
		List<AgentLevel> levels = AgentLevel.dao.findAll();
		renderJson(levels);
	}

	/**
	 * 删除代理商登记
	 */
	public void delete(){
		String id = getPara();
		if(StringUtil.isBlank(id)){
			fail("id不能为空!");
			return;
		}
		ApiResponse apiResponse = AgentService.dao.deleteAgentLevel(id);
		renderJson(apiResponse);
	}

}
